﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Threading;
using System.Reflection;
using UcAsp.Net.BLL;
using UcAsp.Net.Model;
namespace UcAsp.Net.Web.Controllers
{
    public class HomeController : Comm.BaseController
    {
        public ActionResult Index()
        {
            BLL.SettingConfig.Theme(Request.UserAgent);
            string indexId = SysParamBLL.GetParamByName("IndexID");
            if (!string.IsNullOrEmpty(indexId))
            {
                Categories categorie = new BLL.CategoriesBLL().GetCategoriesById(int.Parse(indexId));
                if (categorie != null)
                {
                    return Redirect("/" + categorie.ShowPath + "/index.shtml");
                }
            }

            string indexDefined = SysParamBLL.GetParamByName("IndexDefined");

            if (!string.IsNullOrEmpty(indexDefined))
            {
                UserDefined defined = UserDefinedConfig.GetUserDefined(indexDefined.Trim());
                if (defined != null)
                {
                    return Redirect("/" + indexDefined + ".shtml");
                }
            }
            return View();
        }

        public ActionResult Recommad()
        {
            BLL.SettingConfig.Theme(Request.UserAgent);
            return View();
        }
        //public ActionResult MyIndex(string json)
        //{
        //    if (Session["UserID"] == null)
        //    {
        //        Response.Redirect("/");
        //        Response.End();
        //        return View(new List<Model.Articles>());
        //    }
        //    else
        //    {
        //        int pageindex = Convert.ToInt16(Request.QueryString["i"]) == 0 ? 0 : Convert.ToInt16(Request.QueryString["i"]);

        //        int pagecount = 0;
        //        List<Model.Articles> list = new BLL.ArticlesBLL().Select(int.Parse(Session["UserID"].ToString()), null, false, true, null, 20, pageindex, out pagecount);
        //        if (json != null)
        //        {
        //            return Json(list, JsonRequestBehavior.AllowGet);
        //        }
        //        return View(list);
        //    }
        //}

    }
}
